<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />

    <style type="text/css">
        .class-title {
            margin-top: 10px;
            margin-left: 10px;
            margin-right: 10px;
            font-size: 20px;
            font-weight: bold;
            color: #00BFFF;
        }

        .class-hr {
            margin-top: 5px;
            height: 1px;
            border: none;
            border-top: 1px solid #DCDCDC;
        }

        .class-seqno {
            margin-top: 3px;
            margin-left: 10px;
            margin-right: 25px;
            font-size: 10px;
            color: #808080;
            font-weight: bold;
            text-align: right;
        }

        .class-table {
            width: 100%;
            text-align: left;
            color: black;
            font-size: 13px;
            margin-left: 2%;
            width: 100%;
            table-layout: fixed;
        }

        .class-td {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    </style>
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            来料检验
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:60px;">
        <ul class="aui-list aui-form-list">
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">检测单</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="选择检测单" id="chkBillCode" readonly="true"
                            onclick="goSelectChkBill()" />
                    </div>
                    <i class="aui-input-addon aui-iconfont aui-icon-right" onclick="goSelectChkBill()"></i>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">检测类型</div>
                    <div class="aui-list-item-input">
                        <input type="text" id="chkTypeName" disabled="true">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">物料号</div>
                    <div class="aui-list-item-input">
                        <input type="text" id="mrlCode" disabled="true">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">物料名</div>
                    <div class="aui-list-item-input">
                        <input type="text" id="mrlName" disabled="true">
                    </div>
                </div>
            </li>
        </ul>
    </div>

    <div class='aui-btn aui-btn-info aui-btn-block' style="margin-top:10px;" onclick='closeChkBill()'>进入检测单处理界面</div>

    <div id="divhtml" style="display: block;width:100%;overflow-y: scroll;margin-top:10px;"></div>
    <div style="background-color:white; height: 100%;width: 100%;margin-top:2%;margin-bottom:20%;" id="tbodyHtml">
    </div>
    <div style="background-color:white; height: 100%;width: 100%;margin-top:3%;border:solid 1px #D3D3D3;display:none;margin-bottom:50px;"
        id="tableDiv">
        <table class="table" style='width:100%; font-size:14px;' id="table">
            <tbody>
                <tr>
                    <td style="width:20%;text-align:right;">箱号:</td>
                    <td id="boxnum"></td>
                </tr>
                <tr>
                    <td style="width:20%;text-align:right;">物料编码:</td>
                    <td id="mrlCode"></td>
                </tr>

                <tr>
                    <td style="width:20%;text-align:right;">物料名称:</td>
                    <td id="mrlName"></td>
                </tr>
                <tr>
                    <td style="width:20%;text-align:right;">批次号:</td>
                    <td id="lotCode"></td>
                </tr>
                <tr>
                    <td style="width:20%;text-align:right;">数量:</td>
                    <td id="qty"></td>
                </tr>
            </tbody>
        </table>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">
    var chkBillType = ""; //检测单类型
    var boxnum = "";
    apiready = function () {

        chkBillType = api.pageParam.chkBillType;
    };

    //选择检测单
    function goSelectChkBill() {
        api.openWin({
            name: 'qcmSelectChkBill',
            url: 'qcmSelectChkBill.html',
            pageParam: {
                processState: "0", //审核状态：0未处理，3处理中，7已处理，8已确认，9已取消
                chkBillType: 'LLJC',
                name: "qcmChkBillCl-ac",
            }
        });
    }

    //检测单选择后回调函数
    function setChkBill(id, code, mrlCode, mrlName, opCode, opName, chkTypeName, boxnumBack) {
        $("#chkBillCode").val(code);
        $("#mrlCode").val(mrlCode);
        $("#mrlName").val(mrlName);
        $("#chkTypeName").val(chkTypeName);
        boxnum = boxnumBack;
        // getView();

        //查询检测明细
        // doSearchChkBillDetails();
    }
    // 查询检测单明细项
    function getView() {

        var chkBillCode = $("#chkBillCode").val();
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/searchQcmChkbillCi";
        var data = {
            values: {
                inspection: chkBillCode,
                un: un
            }
        };
        api.showProgress({
            title: '查询中...',
        });
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                api.hideProgress();
                var myobj = eval("(" + data + ")");

                //返回成功
                if (myobj.code == "0") {
                    var list = eval(myobj.list);
                    var html = "";

                    //遍历
                    for (var i = 0; i < list.length; i++) {
                        html += "<div id = '" + list[i].boxnum + "' class='aaui-btn-info aui-btn-block' style='margin-bottom: 10px;color: black !important;background-color: #addbef !important;height: 130px;padding: 0.2rem 0.2rem;font-size: 0.7rem;'>";
                        html += "<table style='width:100%;'>";
                        html += "<tr style='width:100%;'><td style='width:30%;'>箱号：</td><td  id='ctBarcodetital' ' colspan='2'>" + list[i].boxnum + "</td></tr>";
                        html += "<tr style='width:100%;'><td style='width:30%;'>物料编码：</td> <td  id='cellCodetital' ' colspan='3'>" + list[i].mrlCode + "</td></tr>";
                        html += "<tr style='width:100%;'><td style='width:30%;'>物料名称：</td><td id='ext13tital' ' >" + list[i].mrlName + "</td></tr>";
                        html += "<tr style='width:100%;'><td style='width:30%;'>批次号：</td><td id='ext13tital' ' >" + list[i].lotCode + "</td></tr>";
                        html += "<tr style='width:100%;'><td style='width:15%;'>数量：</td><td id='qtytital' >" + list[i].qty + "</td></tr>";
                        html += "</table></div>";
                    }

                    $("#tm").focus();
                    $("#tm").select();
                    idSelector = "tm";

                    $api.html($api.byId("tbodyHtml"), html);
                    $("#uda1").val(myobj.uda1);

                    //失败
                } else if (myobj.code == "1") {
                    $("#chkBillCode").val("");
                    $("#chkBillCode").select();
                    idSelector = "chkBillCode";
                    //清空表格数据
                    $api.html($api.byId("tbodyHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                $("#chkBillCode").val("");
                $("#chkBillCode").select();
                idSelector = "chkBillCode";
                api.hideProgress();
                alert("连接超时，请耐心等待");
            }

        });
    }

    //查询检测单明细项
    // function doSearchChkBillDetails() {

    //     //检测单号
    //     var chkBillCode = $("#chkBillCode").val();

    //     var un = localStorage.getItem('un');
    //     var serverUrl = localStorage.getItem('serverUrl');
    //     var url = serverUrl + "/app/getChkBillDetails";
    //     var data = {
    //         values: {
    //             chkBillCode: chkBillCode,
    //             un: un,
    //         }
    //     };
    //     api.ajax({
    //         url: url,
    //         method: 'post',
    //         dataType: 'json',
    //         timeout: 300,
    //         returnAll: false,
    //         data: data
    //     }, function(ret, err) {
    //         if (ret) {
    //             var data = JSON.stringify(ret);
    //             var myobj = eval("(" + data + ")");
    //             if (myobj.code == '0') {
    //                 var list = eval(myobj.list);

    //                 createTable(list);

    //             } else {
    //                 api.toast({
    //                     msg: myobj.message,
    //                     duration: 3000
    //                 });
    //                 $api.html($api.byId("divhtml"), "");
    //             }
    //         }
    //     });
    // }

    //构造表格数据
    // function createTable(list) {
    //     var html = "";
    //     //遍历
    //     for (var i = 0; i < list.length; i++) {
    //         // 序号
    //         html += "<div class='class-seqno'>";
    //         html += "<span>" + (i + 1) + "</span>";
    //         html += "</div>";
    //         //表格
    //         html += "<div style='margin-left:10px;margin-right:15px;'>";
    //         html += "<table class='class-table'>";
    //         html += "<tr>";
    //         html += "<td class='class-td' colspan = '2'>物料编码:    " + list[i].mrlCode + "</td>";
    //         html += "</tr>";
    //         html += "<tr>";
    //         html += "<td class='class-td' colspan = '2'>物料名称:    " + list[i].mrlName + "</td>";
    //         html += "</tr>";
    //         html += "<tr>";
    //         html += "<tr>";
    //         html += "<td class='class-td' style='width:50%'>批  次  号:    " + list[i].lotCode + "</td>";
    //         html += "<td class='class-td' style='width:50%'>检测数量:    " + list[i].qty + "</td>";
    //         html += "<tr>";
    //         if (list[i].chkResult == "未判定") {
    //             html += "<td class='class-td' style='color:red;'>处理结果:    " + list[i].chkResult + "</td>";
    //         } else {
    //             html += "<td class='class-td' style='color:green;'>处理结果:    " + list[i].chkResult + "</td>";
    //         }
    //         html += "<td class='class-td'><div class='aui-btn aui-btn-info' onclick='deal(\"" + list[i].chkBillDetailsId + "\")'>处理</div></td>";
    //         html += "</tr>";
    //         html += "</table>";
    //         html += "<hr class='class-hr' />";
    //         html += "</div>";
    //     }

    //     $api.html($api.byId("divhtml"), html);
    // }

    //处理
    // function deal(chkBillDetailsId) {
    //     var chkBillCode = $("#chkBillCode").val();

    //     api.openWin({
    //         name: 'qcmChkBillDeal',
    //         url: 'qcmChkBillDeal.html',
    //         pageParam: {
    //             chkBillDetailsId: chkBillDetailsId,
    //             chkBillCode: chkBillCode,
    //             name: "qcmChkBillCl",
    //         }
    //     });
    // }



    //进入检测单处理界面
    function closeChkBill() {
        var chkBillCode = $("#chkBillCode").val();

        if (chkBillCode == null || chkBillCode == "" || chkBillCode == undefined) {
            api.toast({
                msg: "请选择检测单",
                duration: 3000
            });
            return;
        }
        console.log("11111:" + boxnum);
        api.openWin({
            name: 'qcmChkBillDeal-ac',
            url: 'qcmChkBillDeal-ac.html',
            pageParam: {
                chkBillCode: chkBillCode,
                boxnum: boxnum,
                name: "qcmChkBillCl-ac",
            }
        });
    }

    //清空
    function reset() {
        $api.html($api.byId("divhtml"), "");
        $("#chkBillCode").val("");
        $("#mrlCode").val("");
        $("#mrlName").val("");
        $("#chkTypeName").val("");
    }

    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>